******************************************************************
//"农转非"人口政府照护责任认知特征及其生成机制 数据源代码
******************************************************************
//由于对三期数据进行合并和清洗的过程比较复杂，在此不做呈现，对回归结果的复现请使用处理后的数据


//最初的模糊问题：体制分割用于预测和解释民众观念，  那么曾经的体制空间是否会影响民众观念？

//和老师一起反复讨论、推翻和修改 明确所使用核心概念（衔接既有研究）——明确边际贡献——加强理论对话——设计论证结构

//明确解释变量：“农转非”  被解释变量“福利态度（政府照护责任认知）”         

//明确边际贡献： 农转非 和 福利态度 研究交汇的空白点  农转非群体的主观偏好（深层次的市民化）—— 原制度空间对福利态度的影响 

//加强理论对话：为什么原制度空间对福利态度的影响被关注少？   福利态度的制度解释兴起 及其“内生性假设” ——福利态度可变迁 受当下制度空间影响 福利态度不仅是一种外显的偏好 还有其伦理内核  对福利态度的内涵的理解及其解释路径的扩展                                农转非 跨制度转移中的文化延续                                城乡制度差异之外  农村的伦理底蕴  “农民的孩子”  

//对现实实践的进一步启发：福利态度与福利制度间的复杂联系  福利态度能否作为福利政策的重要制定参考


*******代码中中英文字母对照：
//变量处理：变量选项的分布 缺失值情况 极端值情况 样本规模  是否随机样本  已有研究的操作化方法进行重新编码 对“其他”选项进行处理  多使用面板/混合截面  不同年份变量题项的区别  clonevar /gen 生成新变量再做处理  

//多重共线性  检验 
reg welfareattitude2 hukouchangen1 sex work lper_income studyyear fair happy agen religion status 
estat vif
reg govn hukouchangen1 sex work lper_income studyyear fair happy agen religion status filialn
estat vif

welfareattitude2  照护责任认知（1）
govn 照护责任认知（2）
welfareattitude1 照护责任认知（1）二分变量
d161 老人医疗和照护	
d162 老人生活需求	
d163 小孩养育和照顾	
d164 小孩教育费用
hukouchangen1 是否"农转非"
changeyear 获得城市户籍时长（年）
changeway "农转非"路径
sex 性别
work 是否工作
lper_income 家庭人均年收入
studyyear 教育水平
fair 社会公平感知
happy 幸福感
agen 年龄
religion 宗教信仰
status 政治面貌
filialn 孝心
socialconfidence 社会预期
liudongyuqi 阶层流动预期
ziwoxiaoneng 自我效能感  
bentz 本人体制经历
fbtz 父辈体制经历
year 年份
provinces 省份

*****表1
sum2docx welfareattitude2 govn hukouchangen1 changeyear changeway sex work lper_income studyyear fair happy agen religion status filialn socialconfidence liudongyuqi ziwoxiaoneng bentz fbtz year provinces using"Output.docx" if (hukouyearn1>=1958|hukouyearn1==.) & hukou!=1, replace stats(N mean(%9.3f) sd(%9.3f) min(%9.0f) max(%9.0f)) title("table2:描述性统计(2)")  //输出描述性统计表

*****暂元
global control "sex work lper_income studyyear fair happy agen religion status"  

*****表2
*模型1 & 2
oprobit welfareattitude2 hukouchangen1 if sex!=. & work !=. & lper_income!=. & studyyear!=. & fair!=. & happy!=. & agen!=. & religion!=. & status!=. & (hukouyearn1>=1958|hukouyearn1==.)
eststo r1
oprobit welfareattitude2 hukouchangen1 $control i.year i.provinces  if hukouyearn1>=1958|hukouyearn1==.
eststo r2
*模型3
//倾向值匹配
psmatch2 hukouchangen1 sex agen work studyyear lper_income status health bentz fbtz if hukouyearn1>=1958|hukouyearn1==.,outcome(welfareattitude2) kernel ate ties common caliper(.05)  
pstest,both graph
//匹配后数据进行分析
oprobit welfareattitude2 hukouchangen1 $control i.year i.province  if _weight!=. & (hukouyearn1>=1958|hukouyearn1==.)
eststo r3
*模型4 & 5
reg govn hukouchangen1 if sex!=. & health!=. & work !=. & lper_income!=. & studylevel!=. & fair!=. & happy!=. & agen!=. & nation!=. & religion!=. & status!=. & filialn!=. & (hukouyearn1>=1958|hukouyearn1==.)
eststo r4
reg govn hukouchangen1 $control filialn i.provinces if hukouyearn1>=1958|hukouyearn1==.
eststo r5
*模型6
//倾向值匹配
psmatch2 hukouchangen1 sex agen work studyyear lper_income status health bentz fbtz if hukouyearn1>=1958|hukouyearn1==.,outcome(govn) kernel ate ties common caliper(.05)  
pstest,both graph 
//匹配后数据进行分析 
reg govn hukouchangen1 $control filialn i.provinces if _weight!=. & (hukouyearn1>=1958|hukouyearn1==.)
eststo r6
esttab r1 r2 r3 r4 r5 r6 using demo.doc,replace star(* 0.05 ** 0.01 *** 0.001) b(%6.3f ) r2 se

*****表3  均保留农转非经历超过10年的样本
*模型1 农转非经历超过10年的样本
oprobit welfareattitude2 hukouchangen1 $control i.year i.provinces if (hukouyearn1>=1958 & changeyear>10)|hukouyearn1==. 
eststo r1
*模型2 农转非经历超过10年的样本
reg govn hukouchangen1 $control filialn i.provinces if (hukouyearn1>=1958 & changeyear>10)|hukouyearn1==.
eststo r2
*模型3 城乡体制建立前世代 
oprobit welfareattitude2 hukouchangen1 $control i.year i.provinces if [(hukouyearn1>=1958 & changeyear>10)|hukouyearn1==.] & birthyear<1958 
eststo r3
*模型4 城乡体制建立——改革开放世代
oprobit welfareattitude2 hukouchangen1 $control i.year i.provinces if [(hukouyearn1>=1958 & changeyear>10)|hukouyearn1==.] & birthyear<1978 & birthyear>=1958   
eststo r4
*模型5 改革开放世代
oprobit welfareattitude2 hukouchangen1 $control i.year i.provinces if [(hukouyearn1>=1958 & changeyear>10)|hukouyearn1==.] & birthyear>=1978
eststo r5
*模型6 40岁及以下
oprobit welfareattitude2 hukouchangen1 $control i.year i.provinces if [(hukouyearn1>=1958 & changeyear>10)|hukouyearn1==.] & agen<=40 //
eststo r6
*模型7 40以上至60岁及以下
oprobit welfareattitude2 hukouchangen1 $control i.year i.provinces if [(hukouyearn1>=1958 & changeyear>10)|hukouyearn1==.] & agen>40 & agen<=60  
eststo r7
*模型8 60岁以上
oprobit welfareattitude2 hukouchangen1 $control i.year i.provinces if [(hukouyearn1>=1958 & changeyear>10)|hukouyearn1==.] & agen>60 
eststo r8

esttab r1 r2 r3 r4 r5 r6 r7 r8 using demo.doc,replace star(* 0.05 ** 0.01 *** 0.001) b(%6.3f ) r2 se

* 附表A3
//获得城市户籍时长（年/五年为一档）不影响福利态度
oprobit welfareattitude2 changeyear $control i.year i.provinces if hukouyearn1>=1958|hukouyearn1==. 
eststo r1
oprobit welfareattitude2 changeyearn2 $control i.year i.provinces if hukouyearn1>=1958|hukouyearn1==. 
eststo r2
reg govn changeyear $control filialn i.provinces if hukouyearn1>=1958|hukouyearn1==.
eststo r3
reg govn changeyearn2 $control filialn i.provinces if hukouyearn1>=1958|hukouyearn1==.
eststo r4
esttab r1 r2 r3 r4 using demo.doc,replace star(* 0.05 ** 0.01 *** 0.001) b(%6.3f ) r2 se



*****表4  中介效应
*自我效能感
oprobit ziwoxiaoneng hukouchangen1 $control i.provinces if (hukouyearn1>=1958|hukouyearn1==.)& welfareattitude2!=.
eststo r1
oprobit welfareattitude2 hukouchangen1 ziwoxiaoneng $control i.provinces if hukouyearn1>=1958|hukouyearn1==.  //自我效能成立
eststo r2
*阶层流动预期
reg liudongyuqi hukouchangen1 $control i.year i.provinces if (hukouyearn1>=1958|hukouyearn1==.)& welfareattitude2!=.
eststo r3
oprobit welfareattitude2 hukouchangen1 liudongyuqi $control i.year i.provinces if hukouyearn1>=1958|hukouyearn1==.  //流动预期成立
eststo r4
*社会预期
oprobit socialconfidence hukouchangen1 $control i.year i.provinces if (hukouyearn1>=1958|hukouyearn1==.)& welfareattitude2!=.
eststo r5
oprobit welfareattitude2 hukouchangen1 socialconfidence $control i.year i.provinces if hukouyearn1>=1958|hukouyearn1==. //成立
eststo r6
esttab r1 r2 r3 r4 r5 r6 using demo.doc,replace star(* 0.05 ** 0.01 *** 0.001) b(%6.3f ) r2 se


*****表5  中介效应的Bootstrap检验（重复抽取500次）
*自我效能感
capture program drop bootm1
program bootm1, rclass
   oprobit ziwoxiaoneng hukouchangen1 $control i.provinces if (hukouyearn1>=1958|hukouyearn1==.)& welfareattitude2!=.
   matrix a=e(b)
   scalar a1 =a[1,1]
   return scalar a1 =a[1,1]
   oprobit welfareattitude2 hukouchangen1 ziwoxiaoneng $control i.provinces if hukouyearn1>=1958|hukouyearn1==.
   matrix a=e(b)
   scalar a2 =a[1,2]
   return scalar a2 =a[1,2]
   return scalar a3=a1*a2
end
bootstrap  r(a1) r(a2) r(a3), reps(500) seed(1234) nodots: bootm1 
*阶层流动预期
capture program drop bootm1
program bootm1, rclass
   reg liudongyuqi hukouchangen1 $control i.year i.provinces if (hukouyearn1>=1958|hukouyearn1==.)& welfareattitude2!=.
   matrix a=e(b)
   scalar a1 =a[1,1]
   return scalar a1 =a[1,1]
   oprobit welfareattitude2 hukouchangen1 liudongyuqi $control i.year i.provinces if hukouyearn1>=1958|hukouyearn1==.
   matrix a=e(b)
   scalar a2 =a[1,2]
   return scalar a2 =a[1,2]
   return scalar a3=a1*a2
end
bootstrap  r(a1) r(a2) r(a3), reps(500) seed(1234) nodots: bootm1 
*社会预期
capture program drop bootm1
program bootm1, rclass
   oprobit socialconfidence hukouchangen1 $control i.year i.provinces if (hukouyearn1>=1958|hukouyearn1==.)& welfareattitude2!=.
   matrix a=e(b)
   scalar a1 =a[1,1]
   return scalar a1 =a[1,1]
   oprobit welfareattitude2 hukouchangen1 socialconfidence $control i.year i.provinces if hukouyearn1>=1958|hukouyearn1==.
   matrix a=e(b)
   scalar a2 =a[1,2]
   return scalar a2 =a[1,2]
   return scalar a3=a1*a2
end
bootstrap  r(a1) r(a2) r(a3), reps(500) seed(1234) nodots: bootm1 



*****表7 区分"农转非"路径
*照护责任认知（1）
//选择性农转非与原住民比较
oprobit welfareattitude2 hukouchangen1 $control i.year i.provinces if (hukouyearn1>=1958 & changeway==1)|hukouyearn1==.  
eststo r1
//政策性农转非与原住民比较
oprobit welfareattitude2 hukouchangen1 $control i.year i.provinces if (hukouyearn1>=1958 & changeway==0)|hukouyearn1==.
eststo r2
//选择性农转非与政策性农转非比较
psmatch2 changeway sex agen work studyyear lper_income status health bentz fbtz if (hukouyearn1>=1958 |hukouyearn1==.) & hukouchangen1==1,outcome(welfareattitude2) kernel ate ties common caliper(.05)  
pstest,both graph 

oprobit welfareattitude2 changeway $control i.year i.provinces if (hukouyearn1>=1958 |hukouyearn1==.) & hukouchangen1==1 & _weight!=.
eststo r3

*照护责任认知（2）
//选择性农转非与原住民比较
reg govn hukouchangen1 $control filialn i.provinces if (hukouyearn1>=1958 &changeway==1)|hukouyearn1==.
eststo r4
//政策性农转非与原住民比较
reg govn hukouchangen1 $control filialn i.provinces if (hukouyearn1>=1958 &changeway==0)|hukouyearn1==.
eststo r5
//选择性农转非与政策性农转非比较
psmatch2 changeway sex agen work studyyear lper_income status health bentz fbtz if (hukouyearn1>=1958 |hukouyearn1==.) & hukouchangen1==1,outcome(govn) kernel ate ties common caliper(.05)  
pstest,both graph 

reg govn changeway $control filialn i.provinces if (hukouyearn1>=1958|hukouyearn1==.) & hukouchangen1==1 & _weight!=.
eststo r6

esttab r1 r2 r3 r4 r5 r6 using demo.doc,replace star(* 0.05 ** 0.01 *** 0.001) b(%6.3f ) r2 se

*附表A4 排除家属随转（包括通过婚姻）的样本-影响政策性农转非

oprobit welfareattitude2 hukouchangen1 $control i.year i.provinces if (hukouyearn1>=1958 & changeway==0 & changewayn!=6)|hukouyearn1==.
eststo r1
psmatch2 changeway sex agen work studyyear lper_income status health bentz fbtz if (hukouyearn1>=1958 |hukouyearn1==.) & hukouchangen1==1 & changewayn!=6,outcome(welfareattitude2) kernel ate ties common caliper(.05)  
pstest,both graph 

oprobit welfareattitude2 changeway $control i.year i.provinces if _weight!=. & [(hukouyearn1>=1958 |hukouyearn1==.) & changewayn!=6]
eststo r2

reg govn hukouchangen1 $control filialn i.provinces if (hukouyearn1>=1958 &changeway==0 & changewayn!=6)|hukouyearn1==.
eststo r3
psmatch2 changeway sex agen work studyyear lper_income status health bentz fbtz if (hukouyearn1>=1958 |hukouyearn1==.) & hukouchangen1==1 & changewayn!=6,outcome(govn) kernel ate ties common caliper(.05)  
pstest,both graph 

reg govn changeway $control filialn i.provinces if _weight!=. & [(hukouyearn1>=1958 |hukouyearn1==.) & changewayn!=6]
eststo r4

esttab r1 r2 r3 r4  using demo.doc,replace star(* 0.05 ** 0.01 *** 0.001) b(%6.3f ) r2 se

* 附表A5 正文未呈现  基于是否具有体制内工作经历（是否目前工作或上一份工作是体制内工作）来进行分组检验
oprobit welfareattitude2 hukouchangen1 $control i.year i.provinces if  (hukouyearn1>=1958 |hukouyearn1==.) & bentz==1
eststo r1
oprobit welfareattitude2 hukouchangen1 $control i.year i.provinces if  (hukouyearn1>=1958 |hukouyearn1==.) & bentz==0  
eststo r2
reg govn hukouchangen1 $control filialn i.provinces if (hukouyearn1>=1958|hukouyearn1==.) & bentz==1
eststo r3
reg govn hukouchangen1 $control filialn i.provinces if (hukouyearn1>=1958|hukouyearn1==.) & bentz==0
eststo r4
esttab r1 r2 r3 r4  using demo.doc,replace star(* 0.05 ** 0.01 *** 0.001) b(%6.3f ) r2 se


*****附表1 稳健性检验（1）logit模型/替换被解释变量
*ologit模型
ologit welfareattitude2 hukouchangen1 $control i.year i.provinces if hukouyearn1>=1958|hukouyearn1==.
eststo r1
*二分变量 probit模型
probit welfareattitude1 hukouchangen1 $control i.year i.provinces if hukouyearn1>=1958|hukouyearn1==.
eststo r2
*老人医疗和照护	
oprobit d161 hukouchangen1 $control filialn i.provinces if hukouyearn1>=1958|hukouyearn1==.
eststo r3
*老人生活需求
oprobit d162 hukouchangen1 $control filialn i.provinces if hukouyearn1>=1958|hukouyearn1==.
eststo r4
*小孩养育和照顾	
oprobit d163 hukouchangen1 $control filialn i.provinces if hukouyearn1>=1958|hukouyearn1==.
eststo r5
*小孩教育费用
oprobit d164 hukouchangen1 $control filialn i.provinces if hukouyearn1>=1958|hukouyearn1==.
eststo r6

esttab r1 r2 r3 r4 r5 r6 using demo.doc,replace star(* 0.05 ** 0.01 *** 0.001) b(%6.3f ) r2 se

*****附表2  稳健性检验（2）：排除农业户口转为居民户口样本
*照护责任认知（1）
oprobit welfareattitude2 hukouchangen1 $control i.year i.provinces if (hukouyearn1>=1958 & changewayn!=8)|hukouyearn1==.
eststo r1
*PSM
psmatch2 hukouchangen1 sex agen work studyyear lper_income status health bentz fbtz if (hukouyearn1>=1958 & changewayn!=8)|hukouyearn1==.,outcome(welfareattitude2) logit ate kernel common caliper(.05) ties 
pstest,both graph  

oprobit welfareattitude2 hukouchangen1 $control i.year i.province  if _weight!=. & [(hukouyearn1>=1958 & changewayn!=8)|hukouyearn1==.]
eststo r2

*照护责任认知（2）
reg govn hukouchangen1 $control filialn i.provinces if (hukouyearn1>=1958 & changewayn!=8)|hukouyearn1==.
eststo r3
*PSM
psmatch2 hukouchangen1 sex agen work studyyear lper_income status health bentz fbtz if (hukouyearn1>=1958 & changewayn!=8)|hukouyearn1==.,outcome(govn) logit ate kernel common caliper(.05) ties 
pstest,both graph  

reg govn hukouchangen1 $control filialn i.provinces if _weight!=. & [(hukouyearn1>=1958 & changewayn!=8)|hukouyearn1==.]
eststo r4

esttab r1 r2 r3 r4 using demo.doc,replace star(* 0.05 ** 0.01 *** 0.001) b(%6.3f ) r2 se






